package pDatenbank_Zugriff;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import pCocktail_Informationen.Cocktail;

public class db_main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Enter the name of cocktail:");

		String name;
		try {
			name = br.readLine().toString();
			db_main demo = new db_main();
			Cocktail cocktail = demo.getCocktail(name);
			System.out.println(cocktail);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public Cocktail getCocktail(String name) {
		ResultSet rs = null;
		Connection connection = null;
		Statement statement = null;

		Cocktail cocktail = null;
		String query = "SELECT * FROM cocktails WHERE Name=" + name;
		try {
			connection = MySQLAccess.getConnection();
			statement = connection.createStatement();
			rs = statement.executeQuery(query);

			if (rs.next()) {
				cocktail = new Cocktail();
				cocktail.setName(rs.getString("name"));
				cocktail.setZutaten(rs.getString("zutaten"));

			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return cocktail;
	}

	public Cocktail addCocktail() {
		Cocktail cocktail = null;
		return cocktail;
	}
}
